package com.jkc.xh.fragments.core;

import android.view.View;
import android.widget.ListView;


import com.jkc.xh.R;
import com.jkc.xh.views.widget.loadmore.LoadMoreListViewContainer;
import com.jkc.xh.views.widget.pullview.PullListView;
import com.jkc.xh.views.widget.pullview.core.ListViewPlus;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

import in.srain.cube.views.ptr.PtrFrameLayout;

@EFragment
public abstract class BasePullListFragment extends BaseFragment {

    @ViewById(R.id.pull_list_view)
    protected PullListView mPullListView;
    protected static final int PAGE_SIZE = 20;

    @AfterViews
    protected void init() {
        if (mPullListView == null) {
            throw new IllegalArgumentException("布局文件中缺少id为pull_list_view的PullListView");
        }
        initView(mPullListView.getListView());
        mPullListView.setOnPullListener(new PullListView.OnPullListener() {
            @Override
            public void onRefresh(ListViewPlus listView) {
                BasePullListFragment.this.onRefresh(listView);
            }

            @Override
            public void onLoadMore(ListViewPlus listView) {
                BasePullListFragment.this.onLoadMore(listView);
            }
        });
    }

    public void finishLoad(boolean hasMore) {
        mPullListView.finishLoad(hasMore);
    }

    public ListView getListView() {
        return mPullListView.getListView();
    }

    public PtrFrameLayout getRefreshView() {
        return mPullListView.getRefreshView();
    }

    public LoadMoreListViewContainer getLoadMoreView() {
        return mPullListView.getLoadMoreView();
    }

    public void setRefreshHeader(View header) {
        mPullListView.setRefreshHeader(header);
    }

    protected abstract void initView(ListViewPlus listView);

    protected abstract void onRefresh(ListView listView);

    protected abstract void onLoadMore(ListView listView);


}
